<?php
/**
 * Created by PhpStorm.
 * User: Yangjinlei
 * Date: 2018/6/27
 * Time: 11:05
 */

namespace App\Traits;


use Response as CommonResponse;

trait Response
{
    private $debug = [];
    public function response($code,$message,$data=[],$header=[]){
        $ResponseData = [
            'code'  =>  $code,
            'msg'   =>  $message
        ];

//        if (count($data))
        $ResponseData['data'] = $data;
        if (count($this->debug))
            $ResponseData['debug'] = $this->debug;
        return CommonResponse::json($ResponseData,200,$header);
    }

    public function success($info=[],$code=200,$message='成功')
    {
        return $this->response($code,$message,$info);
    }

    public function failed($code,$message='失败')
    {
        return $this->response($code,$message);
    }

    //列表获取的标准方式
    public function page($list,$count=0){
        $data = ['list'=>$list,'count'=>$count];
        return $this->success($data);
    }
    /**
     * @param $params
     */
    public function debug($params){
        array_push($this->debug,$params);
    }
}